﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;

namespace DTcms.Web.m
{
    /// <summary>
    /// company 的摘要说明
    /// </summary>
    public class company : IHttpHandler, IRequiresSessionState
    {
        protected int totalCount = 0;
        public void ProcessRequest(HttpContext context)
        {
            //取得处事类型
            string action = DTRequest.GetQueryString("action");

            switch (action)
            {
                case "get_index": //首页内容
                    get_index(context);
                    break;
                case "get_about": //公司简介
                    get_about(context);
                    break;
                case "get_product_list": //产品列表
                    get_product_list(context);
                    break;
                case "get_xiangce_list": //相册
                    get_xiangce_list(context);
                    break;
                case "guestbook_save": //公司简介
                    guestbook_save(context);
                    break;
                case "get_xinxi_list": //获取发布动态列表
                    get_xinxi_list(context);
                    break;
                case "get_company_category": //获取店铺产业分类
                    get_company_category(context);
                    break;
                case "get_company_jixie_category": //获取店铺产业分类
                    get_company_jixie_category(context);
                    break;
            }
        }

        #region 首页内容=============================
        private void get_index(HttpContext context)
        {
            int _company_id = DTRequest.GetQueryInt("company_id");
            if (_company_id == 0)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"错误提示：参数不正确！\"}");
                return;
            }
            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            //获取user_name
            int company_user_id = new BLL.users().GetUserID(_company_id);
            string company_user_name = new BLL.users().GetUserName(company_user_id);
            int company_user_group= new BLL.users().GetGroupID(company_user_id);
            strTxt.Append("\"company_user_id\":" + company_user_id);
            strTxt.Append(",\"company_user_name\":\"" + company_user_name + "\"");
            strTxt.Append(",\"company_user_group_id\":\"" + company_user_group + "\"");
            //获取求购信息
            BLL.product bll1 = new BLL.product();
            DataSet ds1 = bll1.GetList(9, "status=1 and company_id=" + _company_id, " add_time desc");
            //如果记录存在
            if (ds1.Tables[0].Rows.Count > 0)
            {
                strTxt.Append(",\"product_list\":[");
                for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds1.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append(",\"market_price\":\"" + dr["price"] + "\"");
                    strTxt.Append(",\"unit\":\"" + dr["unit"] + "\"");
                    string proimg = dr["img_url"].ToString();
                    if (proimg.Contains("shicaiquanzi"))
                    {
                        if (proimg.Contains("http://")) { strTxt.Append(",\"img_url\":\"" + proimg + "\""); }
                        else { strTxt.Append(",\"img_url\":\"http://" + proimg + "\""); }
                    }
                    else
                    {
                        strTxt.Append(",\"img_url\":\"http://pic.shicaiquanzi.com" + proimg + "\"");
                    }
                    //if (proimg.Contains("shicaiquanzi"))
                    //{
                    //    strTxt.Append(",\"img_url\":\"http:\\/\\/" + proimg + "\"");
                    //}
                    //else
                    //{
                    //    strTxt.Append(",\"img_url\":\"http:\\/\\/www.shicaiquanzi.com" + proimg + "\"");
                    //}

                    Model.product modelProduct = bll1.GetModel(int.Parse(dr["id"].ToString()));
                    if (modelProduct.albums != null)
                    {
                        strTxt.Append(",\"pic_list\":[");
                        int ii = 0;
                        foreach (Model.common_albums modelt in modelProduct.albums)
                        {
                            ii++;
                            if (modelt.original_path.Contains("shicaiquanzi"))
                            {
                                if (modelt.original_path.Contains("http://")) { strTxt.Append("{\"picurl\":\"" + modelt.original_path + "\"}"); }
                                else { strTxt.Append("{\"picurl\":\"http://" + modelt.original_path + "\"}"); }
                            }
                            else
                            {
                                strTxt.Append("{\"picurl\":\"http://pic.shicaiquanzi.com" + modelt.original_path + "\"}");
                            }
                            //if (modelt.original_path.Contains("shicaiquanzi"))
                            //{
                            //    strTxt.Append("{\"picurl\":\"http://" + modelt.original_path + "\"}");
                            //}
                            //else
                            //{
                            //    strTxt.Append("{\"picurl\":\"http://www.shicaiquanzi.com" + modelt.original_path + "\"}");
                            //}
                            //是否加逗号
                            if (ii < modelProduct.albums.Count)
                            {
                                strTxt.Append(",");
                            }
                        }
                        strTxt.Append("]");
                    }
                    
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds1.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("],");
            }
            else
            {
                strTxt.Append(",\"product_list\":[],");
            }
            //获取相册列表
            BLL.xiangce bll5 = new BLL.xiangce();
            DataSet ds5 = bll5.GetList(9, "company_id=" + _company_id, "sort_id desc,add_time desc");
            //如果记录存在
            if (ds5.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("\"photo_list\":[");
                for (int i = 0; i < ds5.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds5.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    string xiangceimg = dr["img_url"].ToString();
                    if (xiangceimg.Contains("shicaiquanzi"))
                    {
                        if (xiangceimg.Contains("http://")) { strTxt.Append(",\"img_url\":\"" + xiangceimg + "\""); }
                        else { strTxt.Append(",\"img_url\":\"http://" + xiangceimg + "\""); }
                    }
                    else
                    {
                        strTxt.Append(",\"img_url\":\"http://pic.shicaiquanzi.com" + xiangceimg + "\"");
                    }

                    //if (xiangceimg.Contains("shicaiquanzi"))
                    //{
                    //    strTxt.Append(",\"img_url\":\"http:\\/\\/" + xiangceimg + "\"");
                    //}
                    //else
                    //{
                    //    strTxt.Append(",\"img_url\":\"http:\\/\\/www.shicaiquanzi.com" + xiangceimg + "\"");
                    //}

                    Model.xiangce modelXiangce = bll5.GetModel(int.Parse(dr["id"].ToString()));
                    if (modelXiangce.albums != null)
                    {
                        strTxt.Append(",\"pic_list\":[");
                        int ii = 0;
                        foreach (Model.common_albums modelt in modelXiangce.albums)
                        {
                            ii++;

                            if (modelt.original_path.Contains("shicaiquanzi"))
                            {
                                if (modelt.original_path.Contains("http://")) { strTxt.Append("{\"picurl\":\"" + modelt.original_path + "\"}"); }
                                else { strTxt.Append("{\"picurl\":\"http://" + modelt.original_path + "\"}"); }
                            }
                            else
                            {
                                strTxt.Append("{\"picurl\":\"http://pic.shicaiquanzi.com" + modelt.original_path + "\"}");
                            }

                            //if (modelt.original_path.Contains("shicaiquanzi"))
                            //{
                            //    strTxt.Append("{\"picurl\":\"http://" + modelt.original_path + "\"}");
                            //}
                            //else
                            //{
                            //    strTxt.Append("{\"picurl\":\"http://www.shicaiquanzi.com" + modelt.original_path + "\"}");
                            //}
                            //是否加逗号
                            if (ii < modelXiangce.albums.Count)
                            {
                                strTxt.Append(",");
                            }
                        }
                        strTxt.Append("]");
                    }

                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds5.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("],");
            }
            else
            {
                strTxt.Append("\"photo_list\":[],");
            }
            //获取公司简介等
            BLL.company bll3 = new BLL.company();
            Model.company model = bll3.GetModel(_company_id);
            string _aboutcompany = DTcms.Common.Utils.DropHTML(model.about);
            if (_aboutcompany.Length > 200)
            {
                _aboutcompany = _aboutcompany.Substring(0, 200);
            }
            else { _aboutcompany = DTcms.Common.Utils.DropHTML(model.about); }
            strTxt.Append("\"about\":\"" + Microsoft.JScript.GlobalObject.escape(_aboutcompany) + "...\",");
            strTxt.Append("\"company_name\":\"" + model.title + "\",");
            strTxt.Append("\"zhuying\":\"" + model.pro_remark + "\",");
            strTxt.Append("\"lianxiren\":\"" + model.lianxiren + "\",");
            strTxt.Append("\"telephone\":\"" + model.telphone + "\",");
            strTxt.Append("\"mobile\":\"" + model.mobile + "\",");
            strTxt.Append("\"fax\":\"" + model.fax + "\",");
            strTxt.Append("\"address\":\"" + Microsoft.JScript.GlobalObject.escape(model.address) + "\",");
            strTxt.Append("\"zuobiao\":\"" + model.zuobiao + "\",");
            //2019-02-11 Demon 添加  视频
            if (model.video_url + "" != "")
            {
                strTxt.Append("\"video_url\":\"http://pic.shicaiquanzi.com" + model.video_url + "\",");
            }
            else { strTxt.Append("\"video_url\":\"\","); }

            if (model.video_img + "" != "")
            {
                strTxt.Append("\"video_img\":\"http://pic.shicaiquanzi.com" + model.video_img + "\",");
            }
            else { strTxt.Append("\"video_img\":\"\","); }

            if (model.logo + "" != "")
            {
                if (model.logo.Contains("shicaiquanzi"))
                {
                    if (model.logo.Contains("http://")) { strTxt.Append("\"logo\":\"" + model.logo + "\","); }
                    else { strTxt.Append("\"logo\":\"http://" + model.logo + "\","); }
                }
                else
                {
                    strTxt.Append("\"logo\":\"http://pic.shicaiquanzi.com" + model.logo + "\",");
                }
            }
            else { strTxt.Append("\"logo\":\"../image/default_avatar.png\","); }
            ///### 旧企业黄页banner 图，从原单幅修改为三幅 topimg 不用
            ///### Demon 2018-10-29
            if (!string.IsNullOrEmpty(model.topimg))
            {
                strTxt.Append("\"topimg\":\"http://pic.shicaiquanzi.com" + model.topimg + "\"");
            }
            else
            {
                strTxt.Append("\"topimg\":\"\"");
            }

            ///#### 企业黄页 banner修改  单幅图片为最多三幅，轮播
            ///#### Demon 2018-10-29
            BLL.company_albums bllcomb = new BLL.company_albums();
            DataSet ds8 = bllcomb.GetList(" company_id=" + _company_id);
            if (ds8.Tables[0].Rows.Count > 0)
            {
                strTxt.Append(",\"top_pic_list\":[");
               
                for (int i = 0; i < ds8.Tables[0].Rows.Count; i++)
                {
                   
                    DataRow dr = ds8.Tables[0].Rows[i];
                    strTxt.Append("{\"picurl\":\"" + dr["original_path"] + "\"}");

                  
                    //是否加逗号
                    if (i < ds8.Tables[0].Rows.Count-1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
              
            }
            else
            {
                strTxt.Append(",\"top_pic_list\":[]");
            }

            //获取最新动态
            BLL.xinxi bll = new BLL.xinxi();
           
            DataSet ds = bll.GetList(9, "status < 2  and company_id = " + _company_id, "id desc");
            //DataSet ds1 = bll.GetList(9, "status=1 and company_id=" + _company_id, "id desc");
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append(",\"xinxi_list\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr3 = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"type_id\":" + dr3["type_id"]);
                    strTxt.Append(",\"type_name\":\"" + new BLL.xinxi_type().GetTitle(Convert.ToInt32(dr3["type_id"])) + "\"");
                    strTxt.Append(",\"id\":" + dr3["id"]);
                    strTxt.Append(",\"remark\":\"" + Microsoft.JScript.GlobalObject.escape(dr3["content"].ToString()) + "\"");
                    strTxt.Append(",\"add_time\":\"" + Utils.DateStringFromNow(Convert.ToDateTime(dr3["add_time"])) + "\"");
                    strTxt.Append(",\"hits\":" + dr3["hits"]);
                    strTxt.Append(",\"user_id\":" + dr3["user_id"]);
                    if (Convert.ToInt32(dr3["user_id"]) > 0)
                    {
                        string _username = new BLL.users().GetUserName(Convert.ToInt32(dr3["user_id"]));
                        string _avatar = new BLL.users().GetAvatar(Convert.ToInt32(dr3["user_id"]));
                        strTxt.Append(",\"user_name\":\"" + _username + "\"");
                        if (string.IsNullOrEmpty(_avatar))
                        {
                            strTxt.Append(",\"avatar\":\"../image/default_avatar.png\"");
                        }
                        else
                        {
                            if (_avatar.Contains("shicaiquanzi"))
                            {
                                if (_avatar.Contains("http://")) { strTxt.Append(",\"avatar\":\"" + _avatar + "\""); }
                                else { strTxt.Append(",\"avatar\":\"http://" + _avatar + "\""); }

                            }
                            else
                            {
                                strTxt.Append(",\"avatar\":\"http://pic.shicaiquanzi.com" + _avatar + "\"");
                            }
                        }
                    }

                    BLL.xinxi_albums pbll = new BLL.xinxi_albums();
                    DataSet pds = pbll.GetLists(int.Parse(dr3["id"].ToString()));
                    if (pds.Tables[0].Rows.Count > 0)
                    {
                        strTxt.Append(",\"pic_list\":[");
                        for (int ii = 0; ii < pds.Tables[0].Rows.Count; ii++)
                        {
                            DataRow pdr = pds.Tables[0].Rows[ii];
                            string picurl = pdr["thumb_path"].ToString();
                            if (picurl.Contains("http://"))
                            {
                                strTxt.Append("{\"picurl\":\"" + picurl + "\"}");
                            }
                            else
                            {
                                strTxt.Append("{\"picurl\":\"http://" + pdr["thumb_path"] + "\"}");
                            }
                         
                            //是否加逗号
                            if (ii < pds.Tables[0].Rows.Count - 1)
                            {
                                strTxt.Append(",");
                            }
                        }
                        strTxt.Append("]");
                    }
                    else
                    {
                        strTxt.Append(",\"pic_list\":[]");
                    }

                   

                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");

            }
            else
            {
                strTxt.Append(",\"xinxi_list\":[]");
            }



            ///结束
            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 公司简介=============================
        private void get_about(HttpContext context)
        {
            int _company_id = DTRequest.GetQueryInt("company_id");
            if (_company_id == 0)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"错误提示：参数不正确！\"}");
                return;
            }
            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
           
            //获取公司简介等
            BLL.company bll3 = new BLL.company();
            Model.company model = bll3.GetModel(_company_id);

            strTxt.Append("\"about\":\"" + Microsoft.JScript.GlobalObject.escape(model.about) + "\",");
            strTxt.Append("\"company_name\":\"" + model.title + "\",");
            strTxt.Append("\"zhuying\":\"" + model.pro_remark + "\",");
            strTxt.Append("\"lianxiren\":\"" + model.lianxiren + "\",");
            strTxt.Append("\"telephone\":\"" + model.telphone + "\",");
            strTxt.Append("\"mobile\":\"" + model.mobile + "\",");
            strTxt.Append("\"fax\":\"" + model.fax + "\",");
            strTxt.Append("\"address\":\"" + Microsoft.JScript.GlobalObject.escape(model.address) + "\",");
            if (!string.IsNullOrEmpty(model.topimg))
            {
                strTxt.Append("\"topimg\":\"http://pic.shicaiquanzi.com" + model.topimg + "\"");
            }
            else
            {
                strTxt.Append("\"topimg\":\"\"");
            }

            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 产品展示=============================
        private void get_product_list(HttpContext context)
        {
            int _company_id = DTRequest.GetQueryInt("company_id");
            if (_company_id == 0)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"错误提示：参数不正确！\"}");
                return;
            }
            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            //获取求购信息
            BLL.product bll1 = new BLL.product();
            DataSet ds1 = bll1.GetList(9,1, "status=1 and company_id=" + _company_id, "sort_id desc,add_time desc",out this.totalCount);  
            int total_page = this.totalCount / 9;
            if ((this.totalCount % 9) > 0) { total_page += 1; }
            strTxt.Append("\"total_page\":" + total_page.ToString() + ",");
            //如果记录存在
            if (ds1.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("\"product_list\":[");
                for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds1.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append(",\"market_price\":\"" + dr["price"] + "\"");
                    strTxt.Append(",\"unit\":\"" + dr["unit"] + "\"");
                    string proimg = dr["img_url"].ToString();

                    if (proimg.Contains("shicaiquanzi"))
                    {
                        if (proimg.Contains("http://")) { strTxt.Append(",\"img_url\":\"" + proimg + "\""); }
                        else { strTxt.Append(",\"img_url\":\"http://" + proimg + "\""); }

                    }
                    else
                    {
                        strTxt.Append(",\"img_url\":\"http://pic.shicaiquanzi.com" + proimg + "\"");
                    }
                    //if (proimg.Contains("shicaiquanzi"))
                    //{
                    //    strTxt.Append(",\"img_url\":\"http:\\/\\/" + proimg + "\"");
                    //}
                    //else
                    //{
                    //    strTxt.Append(",\"img_url\":\"http:\\/\\/www.shicaiquanzi.com" + proimg + "\"");
                    //}

                    Model.product modelProduct = bll1.GetModel(int.Parse(dr["id"].ToString()));
                    if (modelProduct.albums != null)
                    {
                        strTxt.Append(",\"pic_list\":[");
                        int ii = 0;
                        foreach (Model.common_albums modelt in modelProduct.albums)
                        {
                            ii++;

                            if (modelt.original_path.Contains("shicaiquanzi"))
                            {
                                if (proimg.Contains("http://")) { strTxt.Append("{\"picurl\":\"" + modelt.original_path + "\"}"); }
                                else { strTxt.Append("{\"picurl\":\"http://" + modelt.original_path + "\"}"); }

                            }
                            else
                            {
                                strTxt.Append("{\"picurl\":\"http://pic.shicaiquanzi.com" + modelt.original_path + "\"}");
                            }

                            //if (modelt.original_path.Contains("shicaiquanzi"))
                            //{
                            //    strTxt.Append("{\"picurl\":\"http://" + modelt.original_path + "\"}");
                            //}
                            //else
                            //{
                            //    strTxt.Append("{\"picurl\":\"http://www.shicaiquanzi.com" + modelt.original_path + "\"}");
                            //}
                            //是否加逗号
                            if (ii < modelProduct.albums.Count)
                            {
                                strTxt.Append(",");
                            }
                        }
                        strTxt.Append("]");
                    }

                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds1.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("],");
            }
            else
            {
                strTxt.Append("\"product_list\":[],");
            }
            //获取公司简介等
            BLL.company bll3 = new BLL.company();
            Model.company model = bll3.GetModel(_company_id);
            if (!string.IsNullOrEmpty(model.topimg))
            {
                strTxt.Append("\"topimg\":\"http://pic.shicaiquanzi.com" + model.topimg + "\"");
            }
            else
            {
                strTxt.Append("\"topimg\":\"\"");
            }
            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 相册展示=============================
        private void get_xiangce_list(HttpContext context)
        {
            int _company_id = DTRequest.GetQueryInt("company_id");
            if (_company_id == 0)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"错误提示：参数不正确！\"}");
                return;
            }
            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");

            //获取相册列表
            BLL.xiangce bll5 = new BLL.xiangce();
            DataSet ds5 = bll5.GetList(9,1, "company_id=" + _company_id, "sort_id desc,add_time desc", out this.totalCount);
            int total_page = this.totalCount /9;
            if ((this.totalCount % 9) > 0) { total_page += 1; }
            strTxt.Append("\"total_page\":" + total_page.ToString() + ",");
            //如果记录存在
            if (ds5.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("\"xiangce_list\":[");
                for (int i = 0; i < ds5.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds5.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    string xiangceimg = dr["img_url"].ToString();

                    if (xiangceimg.Contains("shicaiquanzi"))
                    {
                        if (xiangceimg.Contains("http://")) { strTxt.Append(",\"img_url\":\"" + xiangceimg + "\""); }
                        else { strTxt.Append(",\"img_url\":\"http://" + xiangceimg + "\""); }

                    }
                    else
                    {
                        strTxt.Append(",\"img_url\":\"http://pic.shicaiquanzi.com" + xiangceimg + "\"");
                    }

                    //if (xiangceimg.Contains("shicaiquanzi"))
                    //{
                    //    strTxt.Append(",\"img_url\":\"http:\\/\\/" + xiangceimg + "\"");
                    //}
                    //else
                    //{
                    //    strTxt.Append(",\"img_url\":\"http:\\/\\/www.shicaiquanzi.com" + xiangceimg + "\"");
                    //}

                    Model.xiangce modelXiangce = bll5.GetModel(int.Parse(dr["id"].ToString()));
                    if (modelXiangce.albums != null)
                    {
                        strTxt.Append(",\"pic_list\":[");
                        int ii = 0;
                        foreach (Model.common_albums modelt in modelXiangce.albums)
                        {
                            ii++;

                            if (modelt.original_path.Contains("shicaiquanzi"))
                            {
                                if (xiangceimg.Contains("http://")) { strTxt.Append("{\"picurl\":\"" + modelt.original_path + "\"}"); }
                                else { strTxt.Append("{\"picurl\":\"http://" + modelt.original_path + "\"}"); }

                            }
                            else
                            {
                                strTxt.Append("{\"picurl\":\"http://pic.shicaiquanzi.com" + modelt.original_path + "\"}");
                            }

                            //if (modelt.original_path.Contains("shicaiquanzi"))
                            //{
                            //    strTxt.Append("{\"picurl\":\"http://" + modelt.original_path + "\"}");
                            //}
                            //else
                            //{
                            //    strTxt.Append("{\"picurl\":\"http://www.shicaiquanzi.com" + modelt.original_path + "\"}");
                            //}
                            //是否加逗号
                            if (ii < modelXiangce.albums.Count)
                            {
                                strTxt.Append(",");
                            }
                        }
                        strTxt.Append("]");
                    }
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds5.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("],");
            }
            else
            {
                strTxt.Append("\"xiangce_list\":[],");
            }
            //获取公司简介等
            BLL.company bll3 = new BLL.company();
            Model.company model = bll3.GetModel(_company_id);
            if (!string.IsNullOrEmpty(model.topimg))
            {
                strTxt.Append("\"topimg\":\"http://pic.shicaiquanzi.com" + model.topimg + "\"");
            }
            else
            {
                strTxt.Append("\"topimg\":\"\"");
            }

            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 提交留言信息===========================
        private void guestbook_save(HttpContext context)
        {
            //检查用户是否登录
            string user_name = DTRequest.GetFormString("txtUserName");
            string user_pwd = DTRequest.GetFormString("txtPassword");
            if (string.IsNullOrEmpty(user_name) || string.IsNullOrEmpty(user_pwd))
            {
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }
            Model.users userModel = new BLL.users().GetModel(user_name, user_pwd, 0, 1, true);
            if (userModel == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"您的登录信息有误，请退出系统后重新登录！\"}");
                return;
            }

            BLL.company_guestbook bll = new BLL.company_guestbook();
            Model.company_guestbook model = new Model.company_guestbook();

            string _realname = DTRequest.GetFormString("txtRealName");
            string _mobile = DTRequest.GetFormString("txtMobile");
            string _remark = DTRequest.GetFormString("txtRemark");
            int _company_id = DTRequest.GetFormInt("txtCompanyID");

            if (string.IsNullOrEmpty(_realname))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入您的真实姓名！\"}");
                return;
            }
            if (string.IsNullOrEmpty(_mobile))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入您的手机号！\"}");
                return;
            }

            if (string.IsNullOrEmpty(_remark))
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"对不起，请输入内容！\"}");
                return;
            }

            model.realname = _realname;
            model.mobile = _mobile;
            model.remark = _remark;
            model.user_id = userModel.id;
            model.add_time = DateTime.Now;
            model.status = 0;
            model.company_id = _company_id;

            if (bll.Add(model) > 0)
            {
                context.Response.Write("{\"status\": 1, \"msg\": \"恭喜您，内容提交成功，我们会尽快与您联系！\"}");
                return;
            }
            context.Response.Write("{\"status\": 0, \"msg\": \"对不起，保存过程中发生错误！\"}");
            return;
        }
        #endregion

        #region 最新动态=============================
        private void get_xinxi_list(HttpContext context)
        {
            int _company_id = DTRequest.GetQueryInt("company_id");
            int _type_id = DTRequest.GetQueryInt("type_id");
            if (_company_id == 0)
            {
                context.Response.Write("{\"status\": 0, \"msg\": \"错误提示：参数不正确！\"}");
                return;
            }
            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            //获取求购信息
            BLL.xinxi bll = new BLL.xinxi();
            string sql = " status<2 and company_id=" + _company_id;
            if (_type_id > 0)
            {
                sql += " and type_id=" + _type_id;
            }
            
            DataSet ds = bll.GetList(99, sql, "add_time desc");
            //DataSet ds1 = bll.GetList(9, "status=1 and company_id=" + _company_id, "id desc");
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("\"xinxi_list\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr3 = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"type_id\":" + dr3["type_id"]);
                    strTxt.Append(",\"type_name\":\"" + new BLL.xinxi_type().GetTitle(Convert.ToInt32(dr3["type_id"])) + "\"");
                    strTxt.Append(",\"id\":" + dr3["id"]);
                    strTxt.Append(",\"remark\":\"" + Microsoft.JScript.GlobalObject.escape(dr3["content"].ToString()) + "\"");
                    strTxt.Append(",\"add_time\":\"" + Utils.DateStringFromNow(Convert.ToDateTime(dr3["add_time"])) + "\"");
                    strTxt.Append(",\"hits\":" + dr3["hits"]);
                    strTxt.Append(",\"user_id\":" + dr3["user_id"]);
                    if (Convert.ToInt32(dr3["user_id"]) > 0)
                    {
                        string _username = new BLL.users().GetUserName(Convert.ToInt32(dr3["user_id"]));
                        string _avatar = new BLL.users().GetAvatar(Convert.ToInt32(dr3["user_id"]));
                        strTxt.Append(",\"user_name\":\"" + _username + "\"");
                        if (string.IsNullOrEmpty(_avatar))
                        {
                            strTxt.Append(",\"avatar\":\"../image/default_avatar.png\"");
                        }
                        else
                        {
                            if (_avatar.Contains("shicaiquanzi"))
                            {
                                if (_avatar.Contains("http://")) { strTxt.Append(",\"avatar\":\"" + _avatar + "\""); }
                                else { strTxt.Append(",\"avatar\":\"http://" + _avatar + "\""); }

                            }
                            else
                            {
                                strTxt.Append(",\"avatar\":\"http://pic.shicaiquanzi.com" + _avatar + "\"");
                            }
                        }
                    }

                    BLL.xinxi_albums pbll = new BLL.xinxi_albums();
                    DataSet pds = pbll.GetLists(int.Parse(dr3["id"].ToString()));
                    if (pds.Tables[0].Rows.Count > 0)
                    {
                        strTxt.Append(",\"pic_list\":[");
                        for (int ii = 0; ii < pds.Tables[0].Rows.Count; ii++)
                        {
                            DataRow pdr = pds.Tables[0].Rows[ii];
                            string picurl = pdr["thumb_path"].ToString();
                            if (picurl.Contains("http://"))
                            {
                                strTxt.Append("{\"picurl\":\"" + picurl + "\"}");
                            }
                            else
                            {
                                strTxt.Append("{\"picurl\":\"http://" + pdr["thumb_path"] + "\"}");
                            }
                            //if (picurl.Contains("shicaiquanzi.com"))
                            //{
                            //    strTxt.Append("{\"picurl\":\"http://" + picurl + "\"}");
                            //}
                            //else
                            //{
                            //    strTxt.Append("{\"picurl\":\"http://www.shicaiquanzi.com" + pdr["thumb_path"] + "\"}");
                            //}
                            //是否加逗号
                            if (ii < pds.Tables[0].Rows.Count - 1)
                            {
                                strTxt.Append(",");
                            }
                        }
                        strTxt.Append("]");
                    }
                    else
                    {
                        strTxt.Append(",\"pic_list\":[]");
                    }

                    //获取评论列表
                    BLL.xinxi_comment cbll = new BLL.xinxi_comment();
                    DataSet cds = cbll.GetList(0, "article_id=" + int.Parse(dr3["id"].ToString()), "id desc");
                    if (cds.Tables[0].Rows.Count > 0)
                    {
                        string c_info = string.Empty;
                        for (int c = 0; c < cds.Tables[0].Rows.Count; c++)
                        {
                            DataRow cdr = cds.Tables[0].Rows[c];
                            int _userid = int.Parse(cdr["user_id"].ToString());
                            string _uname = new BLL.users().GetUserName(_userid);
                            c_info += "<p><strong>" + _uname + "：</strong>" + cdr["remark"] + "</p>";
                        }
                        strTxt.Append(",\"common_info\":\"" + Microsoft.JScript.GlobalObject.escape(c_info) + "\"");
                    }
                    else
                    {
                        strTxt.Append(",\"common_info\":\"\"");
                    }

                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                strTxt.Append("\"status\":2,\"xinxi_list\":[]");
            }
            strTxt.Append("}");

            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 获取企业产品分类=============================
        private void get_company_category(HttpContext context)
        {
           
        
            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            //获取求购信息
            BLL.company_category bll = new BLL.company_category();
          

            DataSet ds = bll.GetList(99, " id>0", "sort_id asc,id asc");
            //DataSet ds1 = bll.GetList(9, "status=1 and company_id=" + _company_id, "id desc");
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("\"category_list\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                strTxt.Append("\"status\":2,\"category_list\":[]");
            }
            strTxt.Append("}");

            context.Response.Write(strTxt.ToString());
        }
        #endregion

        #region 获取企业机械分类 二级三级分类=============================
        private void get_company_jixie_category(HttpContext context)
        {


            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            //获取求购信息
            BLL.company_jixie_category bll = new BLL.company_jixie_category();


            DataTable ds = bll.GetList(0, "7");
            //DataSet ds1 = bll.GetList(9, "status=1 and company_id=" + _company_id, "id desc");
            //如果记录存在
            if (ds.Rows.Count > 0)
            {
                strTxt.Append("\"category_list\":[");
                for (int i = 0; i < ds.Rows.Count; i++)
                {
                    DataRow dr = ds.Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr["id"]);
                    strTxt.Append(",\"title\":\"" + dr["title"] + "\"");
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                strTxt.Append("\"status\":2,\"category_list\":[]");
            }
            strTxt.Append("}");

            context.Response.Write(strTxt.ToString());
        }
        #endregion
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}